import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
//拆分常量路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',//重新定向
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }//title时标题设置 icon是图标设置
    }]
  },
]
//拆分异步路由
export const  asyncRouters=[
  {
    path: '/product',
    component: Layout,
    name:'Product',
    //redirect: '/dashboard',重新定向
    meta: { title: '商品管理', icon: 'el-icon-goods' },
    children: [
      {
      path: 'trademake',
      name: 'TradeMake',
      component: () => import('@/views/product/tradeMake/tradeMake'),
      meta: { title: '品牌管理' }//title时标题设置 icon是图标设置
    },
    {
      path: 'attr',
      name: 'Attr',
      component: () => import('@/views/product/Attr/Attr'),
      meta: { title: '平台属性管理' }//title时标题设置 icon是图标设置
    },
    {
      path: 'sku',
      name: 'Sku',
      component: () => import('@/views/product/Sku/Sku'),
      meta: { title: 'Sku管理' }//title时标题设置 icon是图标设置
    },
    {
      path: 'spu',
      name: 'Spu',
      component: () => import('@/views/product/Spu/Spu'),
      meta: { title: 'Spu管理' }//title时标题设置 icon是图标设置
    },
  ]
  },
  {
    name: 'Acl',
    path: '/acl',
    component: Layout,
    redirect: '/acl/user/list',
    meta: {
      title: '权限管理',
      icon: 'el-icon-lock'
    },
    children: [
      {
        name: 'User',
        path: 'user/list',
        component: () => import('@/views/acl/user/list'),
        meta: {
          title: '用户管理',
        },
      },
      {
        name: 'Role',
        path: 'role/list',
        component: () => import('@/views/acl/role/list'),
        meta: {
          title: '角色管理',
        },
      },
      {
        name: 'RoleAuth',
        path: 'role/auth/:id',
        component: () => import('@/views/acl/role/roleAuth'),
        meta: {
          activeMenu: '/acl/role/list',
          title: '角色授权',
        },
        hidden: true,
      },
      {
        name: 'Permission',
        path: 'permission/list',
        component: () => import('@/views/acl/permission/list'),
        meta: {
          title: '菜单管理',
        },
      },
    ]
  },]
//拆分任意路由
export const someRouter=[{ path: '*', redirect: '/404', hidden: true }]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes:constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
